const app = getApp();
Page({
	data: {
		resourceDomain: app.resourceDomain,
		type: 0
	},
	fan_click: function() {
		if (this.url) {
			wx.navigateBack({
				delta: 1
			})
		} else {
			wx.reLaunch({
				url: '../mall/index'
			})
		}
	},
	onLoad: function(options) {
		this.url = options.url;
		// 将options状态值赋给type   如果为空或者是0  为0
		this.setData({
			type: options.status ? options.status : '0'
		})
		var that = this;
		app.request(app.apiDomain + 'index.php?c=user&a=orderlist', {
			status: options.status
		}, function(res) {
			// console.log(res);
			if (res.data.status == '1') {
				for (var i = 0; i < res.data.data.list.length; i++) {
					var a = res.data.data.list[i].f_type;
					var b = '';
					if (a == '105103101') {
						b = 'assist'
					} else if (a == '105103104') {
						b = 'time'
					} else {
						b = 'exchange'
					}
					// console.log(b)
					res.data.data.list[i].f_type = b;
				};
				that.setData({
					orderlist: res.data.data.list,
				});
			};

		});
	},
	del_order:function(e){
		// console.log(e.currentTarget.dataset.order);
		this.setData({
			frame:'on',
			del_data:e.currentTarget.dataset
		});
	},
	order_get:function(){
		var data = this.data.del_data;
		this.data.orderlist.splice(data.index,1)
		this.setData({
			orderlist:this.data.orderlist,
			frame:''
		});
		app.request(app.apiDomain + 'index.php?c=user&a=orderDel', {
			order_no:data.order
		}, function(res) {
			console.log(res.data.info);
		});
	},
	order_off:function(){
		this.setData({
			frame:''
		});
	},
	navigator_click() {
		wx.navigateBack({
			changed: true
		});
	},
	step_click() {
		wx.chooseAddress({
			success: (res) => {
				this.setData({
					step: res.provinceName + '-' + res.cityName + '-' + res.countyName + '-' + res.detailInfo,
					name: res.userName,
					phone: res.telNumber
				})
			},
			fail: function(err) {
				console.log(err)
			}
		})
	},
	onReady: function() {
		app.SystemInfo(this)
	},
	get_click: function(e) {
		// console.log(e)
		app.request(app.apiDomain + "index.php?c=mall&a=toPay&orderNo=343749776519&openid=oSP4V0eMTq-zFeowoUskfQ_JpjL8", {
			orderNo: e.target.dataset.id
		}, function(res) {
			var than = res;
			if (res.data.status == 0) {
				wx.showToast({
					title: res.data.info,
					icon: 'none',
					duration: 2000
				})
				return;
			} else if (res.data.status == 1) {
				wx.requestPayment({
					'timeStamp': res.data.data.timeStamp,
					'nonceStr': res.data.data.nonceStr,
					'package': res.data.data.package,
					'signType': res.data.data.signType,
					'paySign': res.data.data.paySign,
					'success': function(res) {},
					'fail': function(res) {
						wx.showToast({
							title: '支付失败',
							icon: 'none',
							duration: 2000
						})
					},
					'complete': function(res) {
						console.log(res)
						if (res.errMsg == "requestPayment:ok") { // 调用支付成功
							wx.redirectTo({
								url: 'list' //
							})
						} else if (res.errMsg == 'requestPayment:cancel') {
							// 用户取消支付的操作
							wx.showToast({
								title: '已取消支付',
								icon: 'none',
								duration: 2000
							})
						}
					}
				})
			}
		});
	},
	sendFriend(e) {
		wx.navigateTo({
			url: '/pages/activity/sendBless?order_no=' + e.target.dataset.id
		})
	},
	// 切换
	switch (e) {
		console.log(e);
		this.setData({
			type: e.target.dataset.id
		})
		var that = this;
		app.request(app.apiDomain + 'index.php?c=user&a=orderlist', {
			status: e.target.dataset.id
		}, function(res) {
			// console.log(res);
			if (res.data.status == '1') {
				for (var i = 0; i < res.data.data.list.length; i++) {
					var a = res.data.data.list[i].f_type;
					var b = '';
					if (a == '105103101') {
						b = 'assist'
					} else if (a == '105103104') {
						b = 'time'
					} else {
						b = 'exchange'
					}
					// console.log(b)
					res.data.data.list[i].f_type = b;
				};
				that.setData({
					orderlist: res.data.data.list,
				});
			}
		});
	},
	onShareAppMessage: function(e) {
		var wrds = e.target.dataset
		console.log("/pages/mall/detail?type=" + wrds.type + '&goods_id=' + wrds.id);
		return {
			path: "/pages/mall/detail?type=" + wrds.type + '&goods_id=' + wrds.id,
			title: wrds.name,
			imageUrl: app.resourceDomain + wrds.img
		}
	}
})
